﻿using System;
using System.ComponentModel;
using System.Configuration;

namespace mki.Backup.Objects
{
	[ConfigurationCollection(typeof(FTPDeleteElement), AddItemName = "deleteFile", CollectionType = ConfigurationElementCollectionType.BasicMap)]
	public class FTPDeleteSection : CustomConfigurationElementCollection
	{
		#region Properties (3)

		/// <summary>
		/// Gets the type of the <see cref="T:System.Configuration.ConfigurationElementCollection"/>.
		/// </summary>
		/// <value></value>
		/// <returns>The <see cref="T:System.Configuration.ConfigurationElementCollectionType"/> of this collection.</returns>
		[Browsable(false)]
		public override ConfigurationElementCollectionType CollectionType
		{
			get { return ConfigurationElementCollectionType.AddRemoveClearMap; }
		}

		/// <summary>
		/// Gets or sets the <see cref="FTPJobElement"/> at the specified index.
		/// </summary>
		/// <value></value>
		public FTPDeleteElement this[Int32 index]
		{
			get { return BaseGet(index) as FTPDeleteElement; }
			set
			{
				if (BaseGet(index) != null) { BaseRemoveAt(index); }
				BaseAdd(index, value);
			}
		}

		/// <summary>
		/// Gets the <see cref="FTPJobElement"/> with the specified name.
		/// </summary>
		/// <value></value>
		new public FTPDeleteElement this[String name]
		{
			get { return BaseGet(name) as FTPDeleteElement; }
		}

		#endregion Properties

		#region Methods (9)

		// Public Methods (6) 

		/// <summary>
		/// Adds the specified backup job.
		/// </summary>
		/// <param name="backupJob">The backup job.</param>
		public void Add(FTPDeleteElement backupJob)
		{
			BaseAdd(backupJob);
		}

		/// <summary>
		/// Clears this instance.
		/// </summary>
		public void Clear()
		{
			BaseClear();
		}

		/// <summary>
		/// Indexes the of.
		/// </summary>
		/// <param name="backupJob">The backup job.</param>
		/// <returns></returns>
		public int IndexOf(FTPDeleteElement backupJob)
		{
			return BaseIndexOf(backupJob);
		}

		/// <summary>
		/// Removes the specified backup job.
		/// </summary>
		/// <param name="backupJob">The backup job.</param>
		public void Remove(FTPDeleteElement backupJob)
		{
			if (BaseIndexOf(backupJob) >= 0) { BaseRemove(backupJob.Name); }
		}

		/// <summary>
		/// Removes the specified name.
		/// </summary>
		/// <param name="name">The name.</param>
		public void Remove(string name)
		{
			BaseRemove(name);
		}

		/// <summary>
		/// Removes at.
		/// </summary>
		/// <param name="index">The index.</param>
		public void RemoveAt(int index)
		{
			BaseRemoveAt(index);
		}
		// Protected Methods (3) 

		/// <summary>
		/// Adds a configuration element to the <see cref="T:System.Configuration.ConfigurationElementCollection"/>.
		/// </summary>
		/// <param name="element">The <see cref="T:System.Configuration.ConfigurationElement"/> to add.</param>
		protected override void BaseAdd(ConfigurationElement element)
		{
			BaseAdd(element, false);
		}

		/// <summary>
		/// When overridden in a derived class, creates a new <see cref="T:System.Configuration.ConfigurationElement"/>.
		/// </summary>
		/// <returns>
		/// A new <see cref="T:System.Configuration.ConfigurationElement"/>.
		/// </returns>
		protected override ConfigurationElement CreateNewElement()
		{
			return new FTPDeleteElement();
		}

		/// <summary>
		/// Gets the element key for a specified configuration element when overridden in a derived class.
		/// </summary>
		/// <returns>
		/// An <see cref="T:System.Object"/> that acts as the key for the specified <see cref="T:System.Configuration.ConfigurationElement"/>.
		/// </returns>
		/// <param name="element">The <see cref="T:System.Configuration.ConfigurationElement"/> to return the key for. </param>
		protected override object GetElementKey(ConfigurationElement element)
		{
			return ((FTPDeleteElement)element).Name;
		}

		#endregion Methods
	}
}